

enum BTN {
    //% block="x"
    x,
    //% block="y"
    y,
    //% block="z"
    z
}


//% color="#ff9f06" iconWidth=50 iconHeight=40
namespace lis2dw12 {

    //% block="initialization LIS2DW12 IIC address 0x18 " blockType="command"
     export function initialization(parameter: any, block: any) {
        Generator.addInclude('lisinc', '#include <DFRobot_LIS2DW12.h>');
        Generator.addObject(`lisobj`, `DFRobot_LIS2DW12_I2C`, `acce;`);
		Generator.addDefine(`LIS2DW12_CS`,`3`);
		Generator.addSetup(`Serial.begin`,`Serial.begin(9600);`);
        Generator.addSetup(`acce.begin`, `while(!acce.begin()){
     Serial.println("Communication failed, check the connection and I2C address setting when using I2C communication.");
     delay(1000);
  }
  Serial.print("chip id : ");
  Serial.println(acce.getID(),HEX);`);
		Generator.addSetup(`acce.softReset`,`acce.softReset();`);
		Generator.addSetup(`acce.continRefresh`,`acce.continRefresh(true);`);
		Generator.addSetup(`acce.setDataRate`,`acce.setDataRate(DFRobot_LIS2DW12::eRate_50hz);`);
		Generator.addSetup(`acce.setRange`,`acce.setRange(DFRobot_LIS2DW12::e2_g);`);
		Generator.addSetup(`acce.setFilterPath`,`acce.setFilterPath(DFRobot_LIS2DW12::eLPF);`);
		Generator.addSetup(`acce.setFilterBandwidth`,`acce.setFilterBandwidth(DFRobot_LIS2DW12::eRateDiv_4);`);
		Generator.addSetup(`acce.setPowerMode`,`acce.setPowerMode(DFRobot_LIS2DW12::eContLowPwrLowNoise2_14bit);`);
		Generator.addSetup(`dadada1`,`Serial.println("Acceleration:");`);
		Generator.addSetup(`adadadz`,`delay(100);`);
		
        //Generator.addCode(`myoled.setCursorLine(${add});\n\tmyoled.printLine();`);
    }
	
	//% block="red [msg]" blockType="reporter"
	//% msg.shadow="dropdownRound" msg.options="BTN" BTN.defl="SIZE.x"
    export function getmsg(parameter: any, block: any) {
		let button = parameter.msg.code;
		if (button === 'x') {
		Generator.addCode(`acce.readAccX()`);
		}else if (button === 'y') {
               Generator.addCode(`acce.readAccY()`);
        } else if (button === 'z') {
               Generator.addCode(`acce.readAccZ()`);
        }
        
    }

   
}
